﻿Imports System.Data.OracleClient
Imports System.Data
Imports ccapps.persistent

Public Class BSCSConfigReport

    Const RootTreeMainNodeDescription As String = "PostPaid Sorgular"

    Private Function GetTreeNode(_Value As String, _Text As String) As TreeNode

        Dim Node As New TreeNode()
        Node.Value = _Value
        Node.Text = _Text

        Return Node
    End Function

    Public Function GetMenu() As TreeView
        Dim DataEngine As New BSCSConfigReport_DAO()
        Dim PageInterface As New BSCSConfigReportPage()

        Dim TreeviewMenu As New TreeView()

        Dim TreeMenuDataTable As DataTable
        Dim TreeSubMenuDataTable As DataTable

        TreeMenuDataTable = DataEngine.GetMenuDataTable()

        Dim MainNode As New TreeNode()
        MainNode = GetTreeNode(RootTreeMainNodeDescription, RootTreeMainNodeDescription)
        TreeviewMenu.Nodes.Add(MainNode)

        If TreeMenuDataTable.Rows.Count > 0 Then
            For i As Integer = 0 To TreeMenuDataTable.Rows.Count - 1
                Dim SubNode As New TreeNode()
                Dim NodeDescription As String = TreeMenuDataTable.Rows(i).Item(2).ToString()
                SubNode = GetTreeNode(NodeDescription, NodeDescription)
                MainNode.ChildNodes.Add(SubNode)

                TreeSubMenuDataTable = DataEngine.GetSubMenuDataTable(TreeMenuDataTable.Rows(i).Item(0))

                For j As Integer = 0 To TreeSubMenuDataTable.Rows.Count - 1
                    Dim ChildNode As New TreeNode()
                    ChildNode = GetTreeNode(TreeSubMenuDataTable.Rows(j).Item(0), TreeSubMenuDataTable.Rows(j).Item(1))
                    SubNode.ChildNodes.Add(ChildNode)
                Next
            Next
        End If

        Return TreeviewMenu
    End Function

    Public Function GetConfigSQLDataTable(_ConfigId As Integer, _SortExpression As String, _PageIndex As Integer, _PageSize As Integer, _SearchStatement As String) As DataTable

        Dim DataEngine As New BSCSConfigReport_DAO()
        Return DataEngine.GetConfigSQLDataTable(_ConfigId, _SortExpression, _PageIndex, _PageSize, _SearchStatement)

    End Function

    Public Function GetUsageDescription(_ConfigId As Integer) As String

        Dim DataEngine As New BSCSConfigReport_DAO()
        Return DataEngine.GetUsageDescription(_ConfigId)

    End Function

    Public Function GetRowCount(_ConfigId As Integer, _SearchStatement As String) As Integer

        Dim DataEngine As New BSCSConfigReport_DAO()
        Return DataEngine.GetRowCount(_ConfigId, _SearchStatement)
    End Function

    Public Function GetConfigSqlResultMetaData(_ConfigId) As DataTable

        Dim DataEngine As New BSCSConfigReport_DAO()
        Return DataEngine.GetConfigSqlResultMetaData(_ConfigId)
    End Function

    Public Function CheckAuthorization() As Boolean

        Dim AuthorizationDataTable As System.Data.DataTable
        AuthorizationDataTable = authorization.Get_Author(GlobalVar.userID)

        If AuthorizationDataTable.Rows.Count = 0 Then
            Return False
        End If

        Return True

    End Function

    Public Function LogFailure(_LogMessage As String)

        Dim DataEngine As New BSCSConfigReport_DAO()
        DataEngine.LogFailure(_LogMessage)

    End Function

    Public Function GetHelpText(_ShortDescription As String) As String

        Dim DataEngine As New BSCSConfigReport_DAO()
        Return DataEngine.GetHelpText(_ShortDescription)

    End Function

End Class


